package com.pro.service.imple;

import com.pro.mapper.JsUserCouponMapper;
import com.pro.pojo.JsUserCoupon;
import com.pro.pojo.JsUserCouponUsed;
import com.pro.service.JsUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsUserCouponServiceImple
 * Package:com.pro.service.imple
 * Description: 优惠券ServiceImple
 *
 * @Date:2022/1/10 下午 3:39
 * @Author: WYH
 */
@Service
public class JsUserCouponServiceImple implements JsUserCouponService {

    @Autowired(required = false)
    private JsUserCouponMapper jsUserCouponMapper;

    /**
     * @Author WYH
     * @Description //TODO 查询微圈列表中数据
     * @Date 下午 3:24 2022/1/12
     * @Param couponName,online,grant，startDate，endDate，limit，page
     * @return  List<JsUserCoupon>
     **/
    @Override
    public List<JsUserCoupon> getAllCoupon(String couponName, String online, String grant, String startDate, String endDate, Integer limit, Integer page) {
        page = (page-1)*limit;
        List<JsUserCoupon> allCoupon = jsUserCouponMapper.getAllCoupon(couponName,online,grant,startDate,endDate,limit, page);
        return allCoupon;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算总条数
     * @Date 下午 3:24 2022/1/12
     * @Param
     * @return  Integer
     **/
    @Override
    public Integer count() {
        Integer count = jsUserCouponMapper.count();
        return count;
    }

    /**
     * @Author WYH
     * @Description //TODO 修改上线状态
     * @Date 下午 3:24 2022/1/12
     * @Param couponId，online，updateId，updateDate
     * @return true | false
     **/
    @Override
    public Boolean updateCoupon(Integer couponId, Integer online, Integer updateId, Date updateDate) {
        updateDate = new Date();
        Boolean aBoolean = jsUserCouponMapper.updateCoupon(couponId, online, updateId, updateDate);
        return aBoolean;
    }

    /**
     * @Author WYH
     * @Description //TODO 删除优惠券
     * @Date 下午 3:24 2022/1/12
     * @Param couponId
     * @return true | false
     **/
    @Override
    public Boolean delCoupon(Integer couponId) {
        Boolean aBoolean = jsUserCouponMapper.delCoupon(couponId);
        return aBoolean;
    }

    /**
     * @Author WYH
     * @Description //TODO 查询优惠券详情
     * @Date 下午 3:24 2022/1/12
     * @Param couponId
     * @return JsUserCoupon
     **/
    @Override
    public JsUserCoupon seeCoupon(Integer couponId) {
        JsUserCoupon jsUserCoupon = jsUserCouponMapper.seeCoupon(couponId);
        return jsUserCoupon;
    }

    /**
     * @Author WYH
     * @Description //TODO 添加优惠券
     * @Date 下午 8:16 2022/1/12
     * @Param   jsUserCoupon
     * @return true | false
     **/
    @Override
    public Boolean addCoupon(JsUserCoupon jsUserCoupon) {
        jsUserCoupon.setCreateDate(new Date());
        Boolean addCouponBoolean = jsUserCouponMapper.addCoupon(jsUserCoupon);
        return addCouponBoolean;
    }

    /**
     * @Author WYH
     * @Description //TODO 查询用户优惠券
     * @Date 上午 9:49 2022/1/13
     * @Param limit,page
     * @return  List<JsUserCoupon>
     **/
    @Override
    public List<JsUserCoupon> getAllUserCoupon(String account,String nickname,Integer limit, Integer page) {
        page = (page-1)*limit;
        List<JsUserCoupon> allUserCoupon = jsUserCouponMapper.getAllUserCoupon(account,nickname,limit, page);
        return allUserCoupon;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算用户优惠券个数
     * @Date 上午 10:57 2022/1/13
     * @Param
     * @return
     **/
    @Override
    public Integer userCount(String account,String nickname) {
        Integer integer = jsUserCouponMapper.userCount(account,nickname);
        return integer;
    }

    /**
     * @Author WYH
     * @Description //TODO 赠送优惠券中的查询优惠券
     * @Date 下午 7:28 2022/1/13
     * @Param couponName,limit,page
     * @return List<JsUserCoupon>
     **/
    @Override
    public List<JsUserCoupon> getCouponGive(String couponName, Integer limit, Integer page) {
        page = (page-1)*limit;
        List<JsUserCoupon> couponGive = jsUserCouponMapper.getCouponGive(couponName, limit, page);
        return couponGive;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算赠送优惠券中的查询优惠券个数
     * @Date 下午 7:33 2022/1/13
     * @Param couponName
     * @return  Integer
     **/
    public Integer GiveCount(String couponName){
        Integer giveCount = jsUserCouponMapper.GiveCount(couponName);
        return giveCount;
    }

    /**
     * @Author WYH
     * @Description //TODO 为用户添加一个或多个优惠券
     * @Date 下午 8:31 2022/1/13
     * @Param List<JsUserCouponUsed>
     * @return  true | false
     **/
    public Boolean addGiveCoupon(List<JsUserCouponUsed> jsUserCouponUsed){
        for (JsUserCouponUsed CouponUsed : jsUserCouponUsed) {
            CouponUsed.setGetDate(new Date());
        }
        Boolean addGiveCoupon = jsUserCouponMapper.addGiveCoupon(jsUserCouponUsed);
        return addGiveCoupon;
    }
}
